from django.db import models
from django.contrib.auth import get_user_model
from shopping.models import Food_vegetables
from django.utils.timezone import now
# Create your models here.

User = get_user_model()
class Comments(models.Model):
    user = models.ForeignKey(User,verbose_name="评论用户",on_delete=None,null=True)
    commodity = models.ForeignKey(Food_vegetables,verbose_name="评论商品",on_delete=None,null=True)
    content = models.TextField(max_length=2000, verbose_name="评论")
    time = models.DateTimeField(default=now, verbose_name="评论时间")
    def __str__(self):
        return "用户id:{},对商品{}的评论".format(self.user.id, self.commodity.name)

    class Meta:
        verbose_name = "商品评论"
        verbose_name_plural = verbose_name
        unique_together = ("user","commodity")